﻿// =================================================================== 
// 项目说明
//====================================================================
// sushee @Copy Right 2019
// 文件： SmsPlaceHolderRepository.cs
// 项目名称：斑马车务
// 创建时间：2019/9/25
// 负责人：sushee
// ===================================================================
using System;
using System.Text;
using System.Collections.Generic;
using Dapper;
using YouWei.Infrastructure.Entity;

namespace YouWei.Infrastructure.Repository
{
	/// <summary>
	/// 仓储层
	/// </summary>	
	public class SmsPlaceHolderRepository:BaseRepository<SmsPlaceHolder>
	{		
    
        #region 构造

        public SmsPlaceHolderRepository() : base(){}

        public SmsPlaceHolderRepository(string connectionString) : base(connectionString){}

        public SmsPlaceHolderRepository(DatabaseContext dbContext) : base(dbContext){}

        #endregion

	    public SmsPlaceHolder GetRandomPlaceHolder(int templateID,string carBrand, string carSerial,int orderNumber)
	    {
	        string szSql = @"SELECT 
	                            TOP 1 * 
                            FROM SmsPlaceHolder
                            WHERE TemplateID=@TemplateID
                            AND CarBrand=@CarBrand                       
                            AND CarSerial=@CarSerial
                            AND OrderNumber=@OrderNumber
                             ORDER BY NEWID()";
	        return dbContext.Connection.QueryFirstOrDefault<SmsPlaceHolder>(szSql, new { TemplateID=templateID, CarBrand =carBrand, CarSerial =carSerial, OrderNumber =orderNumber});
	    }

        public SmsPlaceHolder GetTemplatePlaceHolder(int templateID,  int orderNumber)
        {
            string szSql = @"SELECT 
	                            TOP 1 * 
                            FROM SmsPlaceHolder
                            WHERE TemplateID=@TemplateID
                            AND OrderNumber=@OrderNumber
                            AND IsDeleted=0
                            ORDER BY NEWID()";
            return dbContext.Connection.QueryFirstOrDefault<SmsPlaceHolder>(szSql, new { TemplateID = templateID, OrderNumber = orderNumber });
        }
    }
}